var _util = require('util/util.js');

var _account_service = {
    checkLogin : function(resolve, reject){
        _util.request({
            url : _util.getServerURL('user/get_login_account_info'),
            method : 'POST',  //用户请求尽量用post
            success : resolve,
            error : reject
        })
    },

    //发送登录请求（账号密码）
    login : function(account, resolve, reject){
        _util.request({
            url : _util.getServerURL('user/login'),
            data : account,
            method : 'POST',  //用户请求尽量用post
            success : resolve,
            error : reject
        })
    },
    //获取图片验证码
    getKaptcha: function (resolve, reject) {
        _util.request({
            url:_util.getServerURL('user/kaptcha'),
            method:'GET',
            success:resolve,
            error:reject
        })
      },

    //发送手机登录请求：
    loginByPhone:function (phone, resolve, reject) {
        _util.request({
            url : _util.getServerURL('user/phoneLogin'),
            data : phone,
            method : 'POST',  //用户请求尽量用post
            success : resolve,
            error : reject
        })
      },

    //请求手机验证码：
    getPhoneCode:function (phoneNumber, resolve, reject) {
        _util.request({
            url : _util.getServerURL('user/phoneCode'),
            data : phoneNumber,
            method : 'POST',  //用户请求尽量用post
            success : resolve,
            error : reject
        })
      },

    //请求已经登陆的用户信息
    getMyAccount:function (resolve, reject) {
        _util.request({
            url : _util.getServerURL('user/get_login_account_info'),
            method : 'POST',  //用户请求尽量用post
            success : resolve,
            error : reject
        })

      },

    //更改一些登陆用户的信息
    updateAccount : function(account, resolve, reject){
        _util.request({
            url : _util.getServerURL('user/update_account'),
            data : account,
            method : 'POST',  //用户请求尽量用post
            success : resolve,
            error : reject
        })
    },

    //退出当前一登陆的账户
    signOut:function (resolve, reject) {
        _util.request({
            url : _util.getServerURL('user/sign_out'),
            method : 'POST',  //用户请求尽量用post
            success : resolve,
            error : reject
        })
      },

    //账号注册：
    register:function (account,resolve,reject) {  
        _util.request({
            url : _util.getServerURL('user/register'),
            method : 'POST',  //用户请求尽量用post
            data : account,
            success : resolve,
            error : reject
        })
    },

    //发送ajax请求，验证用户名是否已经存在
    checkUsername: function(username,resolve,reject){
        _util.request({
            url : _util.getServerURL('user/username'),
            method : 'POST',  //用户请求尽量用post
            data : {username},
            success : resolve,
            error : reject
        })
    }
};

module.exports = _account_service;